package com.zeedev.flyingsaucer.modules.StoreModule.modules;

import android.app.Activity;
import android.content.ContentQueryMap;
import android.database.Cursor;
import com.google.inject.AbstractModule;
import com.google.inject.Provides;
import com.google.inject.name.Named;
import com.zeedev.flyingsaucer.modules.StoreModule.impl.StoreDatabaseModel;
import com.zeedev.flyingsaucer.modules.StoreModule.interfaces.Store;
import mobi.zeedev.flyingsaucer.common.DataModule.FlyingSaucerConv;

/**
 * User: James
 * Date: 12/27/10
 * Time: 9:49 PM
 */
public class StoreModule extends AbstractModule {

    public static final String STORES_LIST_PREFERENCE = "STORES_LIST_PREFERENCE";

    @Override
    protected void configure() {

        bind(Store.class).to(StoreDatabaseModel.class);


    }


//    @Provides
//    Store provideStoreList(Context mContext) {
//        return null;
//    }

//    @Provides
//    @Named("storeMap")
//    HashMap<String, String> provideStoreMap() {
//        //TODO
//        return null;
//    }



    @Provides
    ContentQueryMap providesContentQueryMap(@Named("stores_cursor") Cursor mCursor) {
        return new ContentQueryMap(mCursor, FlyingSaucerConv.Stores.NAME, true, null);
    }

    @Provides
    @Named("stores_cursor")
    Cursor providesStoreCursor(Activity mActivity) {
        Cursor mCursor = mActivity.managedQuery(FlyingSaucerConv.Stores.CONTENT_URI, null,null,null,null);

        return mCursor;
    }


/*    public void bindToPreferences(Context cin) {
        SharedPreferences preferences = cin.getSharedPreferences(STORES_LIST_PREFERENCE, Context.MODE_PRIVATE);
        if (!storeMap.isEmpty()) {
            SharedPreferences.Editor e = preferences.edit();
            e.clear();
            for (Map.Entry<String, String> curEntry : storeMap.entrySet()) {
                e.putString(curEntry.getKey(), curEntry.getValue());
            }
            e.commit();
        }

    }

    public void bindFromPreferences(Context cin) {
        SharedPreferences prefs = cin.getSharedPreferences(STORES_LIST_PREFERENCE, Context.MODE_PRIVATE);
        if (!prefs.getAll().isEmpty()) {
            this.storeMap.clear();
            for (Map.Entry<String, ?> curEntry : prefs.getAll().entrySet()) {
                storeMap.put(curEntry.getKey(), curEntry.getValue().toString());
            }
        }
    }*/



}
